//
//  checkUtil.swift
//  万才信息App
//
//  Created by 陌上互联  on 16/7/15.
//  Copyright © 2016年 万才信息. All rights reserved.
//

import Foundation

class checkUtil {
    
//    检测邮箱地址是否正确
    static func checkEmailCorrect(emailAdress:String)->Bool{
        do {
            let pattern="^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$"
            
            let regex: NSRegularExpression = try NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions.CaseInsensitive)
            let matches = regex.matchesInString(emailAdress, options: NSMatchingOptions.ReportProgress, range: NSMakeRange(0, emailAdress.characters.count))
            return matches.count > 0
        }
        catch {
            return false
        }
    }
    
//    去除HTML标签
    static func removeHtmlTag(json:String)->String{
        do {
            let pattern="<[^>]+>"
            
            let regex: NSRegularExpression = try NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions.CaseInsensitive)
            let result=regex.stringByReplacingMatchesInString(json, options: .ReportProgress, range: NSMakeRange(0, json.characters.count), withTemplate: "")
            
            return result
        }
        catch {
            return ""
        }
    }
    
//    去除回车
    static func removeEnter(json:String)->String{
        do {
            let pattern="\n"
            
            let regex: NSRegularExpression = try NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions.CaseInsensitive)
            let result=regex.stringByReplacingMatchesInString(json, options: .ReportProgress, range: NSMakeRange(0, json.characters.count), withTemplate: "")
            
            return result
        }
        catch {
            return ""
        }

    }
}